<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      width: 500px;
      height: 320px;
      display: flex;
      flex-direction: column;
      margin: 50px auto;
      border: 3px solid #333;
    }

    .box > ul {
      height: 60px;
      display: flex;
    }

    .box > ul > li {
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 30px;
      color: #fff;
      background-color: skyblue;
      cursor: pointer;
    }

    .box > ul > li.active {
      background-color: orange;
    }

    .box > ol {
      flex: 1;
      position: relative;
    }

    .box > ol > li {
      width: 100%;
      height: 100%;
      background-color: purple;
      font-size: 50px;
      color: #fff;
      position: absolute;
      left: 0;
      top: 0;
      display: none;
    }

    .box > ol > li.active {
      display: block;
    }
  </style>
</head>
<body>

  <div class="box">
    <ul>
      <li class="active">1</li>
      <li>2</li>
      <li>3</li>
    </ul>
    <ol>
      <li class="active">1</li>
      <li>2</li>
      <li>3</li>
    </ol>
  </div>
  <script>
      var btns = document.querySelectorAll('ul > li');
      var contents = document.querySelectorAll('ol > li');


      // for(var i=0;i<btns.length;i++){
      //     btns[i].onclick = function(){
      //         alert(i)
      //     }
      // }

      for(let i=0;i<btns.length;i++){
          btns[i].onclick = function(){
              
              // 先移除所有的高量  让所有的内容隐藏  
              for(var j=0;j<btns.length;j++){
                  btns[j].classList.remove('active');
                  contents[j].classList.remove('active');

              }


              // 点击谁 谁高亮  所对应的内容 显示 

              btns[i].classList.add('active');
              contents[i].classList.add('active');


          }
      }


      /* 
            i=3
      {
        btns[0].onclick = function(){alert(i)}   3
      }

      {
        btns[1].onclick = function(){alert(i)}  3
      }

      {
          btns[2].onclick = function(){alert(i)}  3
      }
      



      {
        i=0
        btns[0].onclick = function(){alert(i)}   0
      }

      {
        i=1
         btns[1].onclick = function(){alert(i)}   1
      }

      {
        i=2
        btns[2].onclick = function(){alert(i)}   2
      }
      
      
      
      
      
      */


  </script>
  </body>

  </html>